/*
===========================================================================
This source file is part of DyLab (Dynamic Laboratory)
For the latest info, see http://dylab-modules.googlecode.com

Copyright (c) 2006-2008 Lukas Krejci
(krejci.lukas@volny.cz)

This file is part of DyLab.

    DyLab is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DyLab is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DyLab.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

//===========================================================================================
#include "Ogre_Gfx.h"

//===========================================================================================
dylab::Ogre_Gfx::Camera::Camera(const String & _name, IScene * _scene)
{
    mOgreCamera = dynamicCast<Scene>(_scene)->getOgreSceneMgr()->createCamera(_name);
    DYLAB_ASSERT(mOgreCamera != NULL);    

    // enable polygon mode overrides
    mOgreCamera->setPolygonModeOverrideable(true);
}
//-----------------------------------------------------------------------------
dylab::Ogre_Gfx::Camera::~Camera()
{
}
//-----------------------------------------------------------------------------
dylab::String dylab::Ogre_Gfx::Camera::getName() const
{
    return mOgreCamera->getName();
}
//-----------------------------------------------------------------------------
void dylab::Ogre_Gfx::Camera::setPosition(const Vector3 & _pos)
{
    mOgreCamera->setPosition(toOgreVector3(_pos));
}
//-----------------------------------------------------------------------------
void dylab::Ogre_Gfx::Camera::move(const Vector3 & _pos)           
{
    mOgreCamera->moveRelative(toOgreVector3(_pos));
}
//-----------------------------------------------------------------------------
void dylab::Ogre_Gfx::Camera::rotate(real_t _yaw, real_t _pitch, real_t _roll)
{
    mOgreCamera->yaw(Ogre::Degree(_yaw));
    mOgreCamera->pitch(Ogre::Degree(_pitch));
    mOgreCamera->roll(Ogre::Degree(_roll));
}
//-----------------------------------------------------------------------------
void dylab::Ogre_Gfx::Camera::lookAt(const Vector3 & _target)
{
    mOgreCamera->lookAt(toOgreVector3(_target));
}
//-----------------------------------------------------------------------------
dylab::Ogre_Gfx::Camera::polygon_mode_t dylab::Ogre_Gfx::Camera::getPolygonMode() const
{
    polygon_mode_t polyMode;

    switch (mOgreCamera->getPolygonMode())
    {
    case Ogre::PM_SOLID:
        polyMode = SOLID;
        break;
    case Ogre::PM_WIREFRAME:
        polyMode = WIREFRAME;
        break;
    case Ogre::PM_POINTS:
        polyMode = POINTS;
        break;
    }

    return polyMode;
}
//-----------------------------------------------------------------------------
void dylab::Ogre_Gfx::Camera::setPolygonMode(polygon_mode_t _polygonMode)
{
    switch (_polygonMode)
    {
    case SOLID:
        mOgreCamera->setPolygonMode(Ogre::PM_SOLID);
        break;
    case WIREFRAME:
        mOgreCamera->setPolygonMode(Ogre::PM_WIREFRAME);
        break;
    case POINTS:
        mOgreCamera->setPolygonMode(Ogre::PM_POINTS);
        break;
    }
}
//-----------------------------------------------------------------------------
void dylab::Ogre_Gfx::Camera::setNearClipDistance(real_t _distance)
{
    mOgreCamera->setNearClipDistance(_distance);
}
//-----------------------------------------------------------------------------
void dylab::Ogre_Gfx::Camera::setFarClipDistance(real_t _distance)
{
    mOgreCamera->setFarClipDistance(_distance);
}
//-----------------------------------------------------------------------------
void dylab::Ogre_Gfx::Camera::setAspectRatio(real_t _ratio)
{
    mOgreCamera->setAspectRatio(_ratio);
}
//-----------------------------------------------------------------------------